import request from "superagent";
import {
    serverPath,
    json
} from "../../common/config.js";
import {
    prepareRequest,
    serviceInterceptor
} from "../../common/utils";

class FileService {
    constructor() {

    }

    @serviceInterceptor()
    async uploadFile(file) {
        if (!file) {
            return
        }
        let req = request.post(`${serverPath}files`)
            .attach('file',file)
            .accept(json);
        return await prepareRequest(req);
    }
    @serviceInterceptor()
    async deleteFile(fileName) {
        if (!fileName) {
            return;
        }
        let req = request.post(`${serverPath}files/${fileName}`)
            .accept(json);
        return await prepareRequest(req);
    }
}

export default FileService;